package ihm;

import application.LeGroupe4Administration;
import application.smartcard.CardReadException;
import application.smartcard.CardWriteException;
import application.smartcard.SmartCard;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.Arrays;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

import security.HMAC;
import security.KeyDerivation;
import security.RandomGenerator;

import database.bean.AuthCardData;
import database.bean.User;
import database.hibernate.HibernateUtil;
import enumTypes.Civility;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.smartcardio.CardException;

@SuppressWarnings("serial")
public class AdministrationFrame extends JFrame {

	public static final String INIT_LABEL = "Initialiser";		//label du bouton lorsque la carte est � initialiser
	public static final String REINIT_LABEL = "Reinitialiser";	//label du bouton lorsque la carte est � r�initialiser

	public static final String STATUS_INSERT_CARD = "Inserez votre carte";
	public static final String STATUS_KNOWN_CARD = "Carte reconnue";
	public static final String STATUS_UNKNOWN_CARD = "Carte non repertoriee dans la base de donnees";
	public static final String STATUS_SAVED_CARD = "La carte inseree a ete enregistree";

	public static final String ERROR_ALL_FIELDS_REQUIRED = "Tous les champs sont requis";
	public static final String ERROR_CONFIRM_PASSWORD = "Le mot de passe et sa confirmation sont différents";
	public static final String ERROR_PASSWORD_LENGTH = "La longueur minimale requise du mot de passe est de 8";
	public static final String ERROR_UNSAVED_CARD = "La carte inseree n'a pas ete enregistree";

	public static final int MINIMAL_PASSWORD_LENGTH = 8;


	private  JPanel contentPane;
	private  JLabel cardStatusLabel;
	private  JLabel cardUidLabel;
	private  JButton btn;					//bouton permettant d'initialiser ou r�initialiser la carte
	private  JTextField nomField;
	private  JTextField prenomField;
	private  JPasswordField passwordField;
	private JPasswordField confirmPasswordField;
	@SuppressWarnings("rawtypes")
	private  JComboBox comboBox;

	/**
	 * Test fenetre.
	 */
	public static void main(String[] args) {


		AdministrationFrame f = new AdministrationFrame();
		f.updateFieldEdition(f.getPasswordField(), true);
		f.updateFieldEdition(f.getNomField(), true);
		f.updateFieldEdition(f.getPrenomField(), true);
		f.updateFieldEdition(f.getConfirmPasswordField(), true);
		f.updateLabelText(f.getCardStatusLabel(), STATUS_UNKNOWN_CARD);
		f.updateLabelText(f.getCardUidLabel(), "01235487");
		/**
		 * tests unitaires des fonctions
		 */
		//					frame.updateLabelText(frame.getCardStatusLabel(), "statut");
		//					frame.updateLabelText(frame.getCardUidLabel(), "UID");
		//					
		//					frame.updateButtonText(REINIT_LABEL);
		//					
		//					frame.updateFieldEdition(frame.getPasswordField(), true);
		//					frame.updateComboBoxEdition(frame.getComboBox(), true);

		/**
		 * fin tests unitaires des fonctions
		 */
	}


	/**
	 * Create the frame.
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public AdministrationFrame() {


		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
		setResizable(false);
		setTitle("Création d'un utilisateur");
		setBounds(100, 100, 350, 295);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);

		JPanel dataPanel = new JPanel();
		dataPanel.setBorder(new LineBorder(Color.LIGHT_GRAY));
		contentPane.add(dataPanel, BorderLayout.CENTER);
		GridBagLayout gbl_dataPanel = new GridBagLayout();
		gbl_dataPanel.columnWidths = new int[]{0, 0};
		gbl_dataPanel.rowHeights = new int[]{0, 0, 0};
		gbl_dataPanel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
		gbl_dataPanel.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
		dataPanel.setLayout(gbl_dataPanel);

		JPanel cardDataPanel = new JPanel();
		cardDataPanel.setBorder(new TitledBorder(new LineBorder(new Color(128, 128, 128)), "Donn\u00E9es carte", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(128, 128, 128)));
		GridBagConstraints gbc_cardDataPanel = new GridBagConstraints();
		gbc_cardDataPanel.insets = new Insets(0, 0, 5, 0);
		gbc_cardDataPanel.fill = GridBagConstraints.BOTH;
		gbc_cardDataPanel.gridx = 0;
		gbc_cardDataPanel.gridy = 0;
		dataPanel.add(cardDataPanel, gbc_cardDataPanel);
		GridBagLayout gbl_cardDataPanel = new GridBagLayout();
		gbl_cardDataPanel.columnWidths = new int[]{0, 0, 0, 0};
		gbl_cardDataPanel.rowHeights = new int[]{0, 0, 0};
		gbl_cardDataPanel.columnWeights = new double[]{0.0, 0.0, 1.0, Double.MIN_VALUE};
		gbl_cardDataPanel.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
		cardDataPanel.setLayout(gbl_cardDataPanel);

		JLabel lblStatut = new JLabel("Statut");
		GridBagConstraints gbc_lblStatut = new GridBagConstraints();
		gbc_lblStatut.anchor = GridBagConstraints.WEST;
		gbc_lblStatut.insets = new Insets(0, 0, 5, 5);
		gbc_lblStatut.gridx = 0;
		gbc_lblStatut.gridy = 0;
		cardDataPanel.add(lblStatut, gbc_lblStatut);

		JLabel lblNewLabel = new JLabel(":");
		GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
		gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel.gridx = 1;
		gbc_lblNewLabel.gridy = 0;
		cardDataPanel.add(lblNewLabel, gbc_lblNewLabel);

		cardStatusLabel = new JLabel();
		GridBagConstraints gbc_cardStatusLabel = new GridBagConstraints();
		gbc_cardStatusLabel.fill = GridBagConstraints.HORIZONTAL;
		gbc_cardStatusLabel.insets = new Insets(0, 0, 5, 0);
		gbc_cardStatusLabel.gridx = 2;
		gbc_cardStatusLabel.gridy = 0;
		cardDataPanel.add(cardStatusLabel, gbc_cardStatusLabel);

		JLabel lblUid = new JLabel("UID");
		GridBagConstraints gbc_lblUid = new GridBagConstraints();
		gbc_lblUid.anchor = GridBagConstraints.WEST;
		gbc_lblUid.insets = new Insets(0, 0, 0, 5);
		gbc_lblUid.gridx = 0;
		gbc_lblUid.gridy = 1;
		cardDataPanel.add(lblUid, gbc_lblUid);

		JLabel lblNewLabel_1 = new JLabel(":");
		GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
		gbc_lblNewLabel_1.insets = new Insets(0, 0, 0, 5);
		gbc_lblNewLabel_1.gridx = 1;
		gbc_lblNewLabel_1.gridy = 1;
		cardDataPanel.add(lblNewLabel_1, gbc_lblNewLabel_1);

		cardUidLabel = new JLabel();
		GridBagConstraints gbc_cardUIDLabel = new GridBagConstraints();
		gbc_cardUIDLabel.fill = GridBagConstraints.HORIZONTAL;
		gbc_cardUIDLabel.gridx = 2;
		gbc_cardUIDLabel.gridy = 1;
		cardDataPanel.add(cardUidLabel, gbc_cardUIDLabel);

		JPanel userDataPanel = new JPanel();
		userDataPanel.setBorder(new TitledBorder(new LineBorder(new Color(128, 128, 128)), "Donn\u00E9es utilisateur", TitledBorder.LEADING, TitledBorder.TOP, null, Color.GRAY));
		GridBagConstraints gbc_userDataPanel = new GridBagConstraints();
		gbc_userDataPanel.fill = GridBagConstraints.BOTH;
		gbc_userDataPanel.gridx = 0;
		gbc_userDataPanel.gridy = 1;
		dataPanel.add(userDataPanel, gbc_userDataPanel);
		GridBagLayout gbl_userDataPanel = new GridBagLayout();
		gbl_userDataPanel.columnWidths = new int[]{0, 0, 0, 0};
		gbl_userDataPanel.rowHeights = new int[]{0, 0, 0, 0, 0, 0};
		gbl_userDataPanel.columnWeights = new double[]{0.0, 0.0, 1.0, Double.MIN_VALUE};
		gbl_userDataPanel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		userDataPanel.setLayout(gbl_userDataPanel);

		JLabel lblCivilit = new JLabel("Civilit\u00E9");
		GridBagConstraints gbc_lblCivilit = new GridBagConstraints();
		gbc_lblCivilit.insets = new Insets(0, 0, 5, 5);
		gbc_lblCivilit.anchor = GridBagConstraints.WEST;
		gbc_lblCivilit.gridx = 0;
		gbc_lblCivilit.gridy = 0;
		userDataPanel.add(lblCivilit, gbc_lblCivilit);

		JLabel lblNewLabel_2 = new JLabel(":");
		GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints();
		gbc_lblNewLabel_2.anchor = GridBagConstraints.WEST;
		gbc_lblNewLabel_2.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_2.gridx = 1;
		gbc_lblNewLabel_2.gridy = 0;
		userDataPanel.add(lblNewLabel_2, gbc_lblNewLabel_2);

		comboBox = new JComboBox();
		comboBox.addItem(null);
		comboBox.addItem(Civility.Madame);
		comboBox.addItem(Civility.Mademoiselle);
		comboBox.addItem(Civility.Monsieur);
		GridBagConstraints gbc_comboBox = new GridBagConstraints();
		gbc_comboBox.insets = new Insets(0, 0, 5, 0);
		gbc_comboBox.fill = GridBagConstraints.HORIZONTAL;
		gbc_comboBox.gridx = 2;
		gbc_comboBox.gridy = 0;
		userDataPanel.add(comboBox, gbc_comboBox);

		JLabel lblNom = new JLabel("Nom");
		GridBagConstraints gbc_lblNom = new GridBagConstraints();
		gbc_lblNom.anchor = GridBagConstraints.WEST;
		gbc_lblNom.insets = new Insets(0, 0, 5, 5);
		gbc_lblNom.gridx = 0;
		gbc_lblNom.gridy = 1;
		userDataPanel.add(lblNom, gbc_lblNom);

		JLabel lblNewLabel_3 = new JLabel(":");
		GridBagConstraints gbc_lblNewLabel_3 = new GridBagConstraints();
		gbc_lblNewLabel_3.anchor = GridBagConstraints.WEST;
		gbc_lblNewLabel_3.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_3.gridx = 1;
		gbc_lblNewLabel_3.gridy = 1;
		userDataPanel.add(lblNewLabel_3, gbc_lblNewLabel_3);

		nomField = new JTextField();
		nomField.setEditable(false);
		GridBagConstraints gbc_nomField = new GridBagConstraints();
		gbc_nomField.insets = new Insets(0, 0, 5, 0);
		gbc_nomField.fill = GridBagConstraints.HORIZONTAL;
		gbc_nomField.gridx = 2;
		gbc_nomField.gridy = 1;
		userDataPanel.add(nomField, gbc_nomField);
		nomField.setColumns(10);

		JLabel lblPrnom = new JLabel("Pr\u00E9nom");
		GridBagConstraints gbc_lblPrnom = new GridBagConstraints();
		gbc_lblPrnom.anchor = GridBagConstraints.WEST;
		gbc_lblPrnom.insets = new Insets(0, 0, 5, 5);
		gbc_lblPrnom.gridx = 0;
		gbc_lblPrnom.gridy = 2;
		userDataPanel.add(lblPrnom, gbc_lblPrnom);

		JLabel lblNewLabel_4 = new JLabel(":");
		GridBagConstraints gbc_lblNewLabel_4 = new GridBagConstraints();
		gbc_lblNewLabel_4.anchor = GridBagConstraints.WEST;
		gbc_lblNewLabel_4.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_4.gridx = 1;
		gbc_lblNewLabel_4.gridy = 2;
		userDataPanel.add(lblNewLabel_4, gbc_lblNewLabel_4);

		prenomField = new JTextField();
		prenomField.setEditable(false);
		GridBagConstraints gbc_prenomField = new GridBagConstraints();
		gbc_prenomField.insets = new Insets(0, 0, 5, 0);
		gbc_prenomField.fill = GridBagConstraints.HORIZONTAL;
		gbc_prenomField.gridx = 2;
		gbc_prenomField.gridy = 2;
		userDataPanel.add(prenomField, gbc_prenomField);
		prenomField.setColumns(10);

		JLabel lblMotDePasse = new JLabel("Mot de passe");
		GridBagConstraints gbc_lblMotDePasse = new GridBagConstraints();
		gbc_lblMotDePasse.anchor = GridBagConstraints.WEST;
		gbc_lblMotDePasse.insets = new Insets(0, 0, 5, 5);
		gbc_lblMotDePasse.gridx = 0;
		gbc_lblMotDePasse.gridy = 3;
		userDataPanel.add(lblMotDePasse, gbc_lblMotDePasse);

		JLabel label = new JLabel(":");
		GridBagConstraints gbc_label = new GridBagConstraints();
		gbc_label.insets = new Insets(0, 0, 5, 5);
		gbc_label.anchor = GridBagConstraints.WEST;
		gbc_label.gridx = 1;
		gbc_label.gridy = 3;
		userDataPanel.add(label, gbc_label);

		passwordField = new JPasswordField();
		passwordField.setEditable(false);
		GridBagConstraints gbc_passwordField = new GridBagConstraints();
		gbc_passwordField.insets = new Insets(0, 0, 5, 0);
		gbc_passwordField.fill = GridBagConstraints.HORIZONTAL;
		gbc_passwordField.gridx = 2;
		gbc_passwordField.gridy = 3;
		userDataPanel.add(passwordField, gbc_passwordField);

		JLabel lblConfirmationMotDe = new JLabel("Confirmation mot de passe");
		GridBagConstraints gbc_lblConfirmationMotDe = new GridBagConstraints();
		gbc_lblConfirmationMotDe.insets = new Insets(0, 0, 0, 5);
		gbc_lblConfirmationMotDe.gridx = 0;
		gbc_lblConfirmationMotDe.gridy = 4;
		userDataPanel.add(lblConfirmationMotDe, gbc_lblConfirmationMotDe);

		JLabel label_1 = new JLabel(":");
		GridBagConstraints gbc_label_1 = new GridBagConstraints();
		gbc_label_1.insets = new Insets(0, 0, 0, 5);
		gbc_label_1.anchor = GridBagConstraints.EAST;
		gbc_label_1.gridx = 1;
		gbc_label_1.gridy = 4;
		userDataPanel.add(label_1, gbc_label_1);

		confirmPasswordField = new JPasswordField();
		confirmPasswordField.setEditable(false);
		GridBagConstraints gbc_confirmPasswordField = new GridBagConstraints();
		gbc_confirmPasswordField.fill = GridBagConstraints.HORIZONTAL;
		gbc_confirmPasswordField.gridx = 2;
		gbc_confirmPasswordField.gridy = 4;
		userDataPanel.add(confirmPasswordField, gbc_confirmPasswordField);

		JPanel buttonPanel = new JPanel();
		buttonPanel.setBorder(null);
		contentPane.add(buttonPanel, BorderLayout.SOUTH);

		btn = new JButton(INIT_LABEL);
		btn.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {		
				if(btn.getText().equals(INIT_LABEL)){
					if(prenomField.getText().isEmpty() 
							|| nomField.getText().isEmpty() 
							|| comboBox.getSelectedItem() == null 
							|| passwordField.getPassword().length == 0
							|| confirmPasswordField.getPassword().length == 0){
						JOptionPane.showMessageDialog(AdministrationFrame.this, ERROR_ALL_FIELDS_REQUIRED);
					}else{
						if(passwordField.getPassword().length < MINIMAL_PASSWORD_LENGTH){
							JOptionPane.showMessageDialog(AdministrationFrame.this, ERROR_PASSWORD_LENGTH);
						}
						else{
							if(Arrays.equals(passwordField.getPassword(), confirmPasswordField.getPassword())){
								Session session = HibernateUtil.getSession();
								Transaction tx = session.beginTransaction();

								Civility civility = (Civility) comboBox.getSelectedItem();
								String lastName = nomField.getText();
								String firstName = prenomField.getText();

								User user = new User(lastName, firstName, civility);

								//TODO écrire PIN0 sur la carte pour avoir le droit de modifier les données

								byte[] key = null;
								byte[] salt1 = null;
								byte[] salt2 = null;
								byte[] pin1 = null;
								byte[] pin2 = null;
								byte[] otp = null;
								byte[] pwd = null;
								String ctc2 = null;

								try {
									SmartCard smartCard = LeGroupe4Administration.getSmartCard();

									if(smartCard==null) throw new NoCardException();

									smartCard.resetToDefault();

									if(!SmartCard.hasApduCommandSucceeded(smartCard.presentPin0(SmartCard.PIN0_DEFAULT))){
										throw new CardWriteException();
									}

									key = RandomGenerator.generateSalt(SmartCard.KEY_SIZE); // en clair
									System.out.println("key:"+SmartCard.toHex(key));
									if(!SmartCard.hasApduCommandSucceeded(smartCard.updateKey(key))){
										throw new CardWriteException();
									}

									salt1 = RandomGenerator.generateSalt(SmartCard.SALT_SIZE); // b64
									System.out.println("salt1:"+SmartCard.toHex(salt1));
									salt2 = RandomGenerator.generateSalt(SmartCard.SALT_SIZE); // hmac et b64
									System.out.println("salt2:"+SmartCard.toHex(salt2));
									if(!SmartCard.hasApduCommandSucceeded(smartCard.updateSalt2(salt2))){
										throw new CardWriteException();
									}


									pin1 = KeyDerivation.PBKDF2(new String(passwordField.getPassword()), salt1, SmartCard.PIN_SIZE*8, 10000);
									System.out.println("pin1:"+SmartCard.toHex(pin1));
									if(!SmartCard.hasApduCommandSucceeded(smartCard.updatePin1(pin1))){
										throw new CardWriteException();
									}

									pin2 = RandomGenerator.generateSalt(SmartCard.PIN_SIZE); // b64
									System.out.println("pin2:"+SmartCard.toHex(pin2));
									if(!SmartCard.hasApduCommandSucceeded(smartCard.updatePin2(pin2))){
										throw new CardWriteException();
									}

									otp = RandomGenerator.generateSalt(SmartCard.OTP_SIZE); // hmac et b64
									System.out.println("otp:"+SmartCard.toHex(otp));
									if(!SmartCard.hasApduCommandSucceeded(smartCard.updateOtp(otp))){
										throw new CardWriteException();
									}

									if(!SmartCard.hasApduCommandSucceeded(smartCard.updateAca(SmartCard.ACA_APP))){
										throw new CardWriteException();
									}

									/*
                                                                        if(!SmartCard.hasApduCommandSucceeded(smartCard.SET_CARD_IN_USER_MODE_DEFINITIVE())){
                                                                            throw new CardWriteException();
                                                                        }
									 */


									pwd = KeyDerivation.PBKDF2(new String(pin1), salt2, 128, 10000); // hmac et b64

									ctc2 = HMAC.encodeBase64(smartCard.getCtc2Bytes());

									// en base 64
									String key_b64 = HMAC.encodeBase64(key);
									String salt1_b64 = HMAC.encodeBase64(salt1);
									//String salt2_hmac_b64 = HMAC.encodeBase64(HMAC.hmac_sha256(new String(salt2), salt1));
									String pin2_b64 = HMAC.encodeBase64(pin2);
									String otp_hmac_b64 = HMAC.encodeBase64(HMAC.hmac_sha256(new String(otp), salt2));
									String pwd_hmac_b64 = HMAC.encodeBase64(HMAC.hmac_sha256(new String(pwd), salt2));


									String uid = cardUidLabel.getText();								
									AuthCardData card = new AuthCardData(uid, key_b64, salt1_b64, pin2_b64, ctc2, otp_hmac_b64, pwd_hmac_b64);

									user.setCard(card);
									card.setUser(user);

									session.save(user);
									session.save(card);

									tx.commit();
								} catch (NoSuchAlgorithmException e) {
									e.printStackTrace();
								} catch (InvalidKeySpecException e) {
									e.printStackTrace();
								} catch (CardException ex) {
									Logger.getLogger(AdministrationFrame.class.getName()).log(Level.SEVERE, null, ex);
								} catch (NoCardException ex) {
									Logger.getLogger(AdministrationFrame.class.getName()).log(Level.SEVERE, null, ex);
								} catch (CardWriteException ex) {
									Logger.getLogger(AdministrationFrame.class.getName()).log(Level.SEVERE, null, ex);
								} catch (CardReadException e) {
									e.printStackTrace();
								}

								tx = session.beginTransaction();

								String bdd_cardUID = null;

								List<AuthCardData> cardList = session.createCriteria(AuthCardData.class).add(Restrictions.like("card_uid", getCardUidLabel().getText())).list();
								if(!cardList.isEmpty()){
									bdd_cardUID = cardList.get(0).getCard_uid();
									if(bdd_cardUID.equals(getCardUidLabel().getText())){
										updateLabelText(getCardStatusLabel(), AdministrationFrame.STATUS_SAVED_CARD);
										updateLabelText(getCardUidLabel(), "");
										updateComboBoxValue(getComboBox(), null);
										updateFieldText(getNomField(), "");
										updateFieldText(getPrenomField(), "");
										updateFieldText(getPasswordField(), "");
										updateFieldText(getConfirmPasswordField(), "");
										updateComboBoxEdition(getComboBox(), false);
										updateFieldEdition(getNomField(), false);
										updateFieldEdition(getPrenomField(), false);
										updateFieldEdition(getPasswordField(), false);
										updateFieldEdition(getConfirmPasswordField(), false);
										updateButtonText(INIT_LABEL);
									}
								}
								else{
									JOptionPane.showMessageDialog(AdministrationFrame.this, ERROR_UNSAVED_CARD);
								}

								tx.commit();
								session.close();
							} else {
								JOptionPane.showMessageDialog(AdministrationFrame.this, ERROR_CONFIRM_PASSWORD);
							}

						}
					}
				}else if(btn.getText().equals(REINIT_LABEL)){
					//TODO cas de la perte de mot de passe => "destruction" de la carte ?
				}
			}

		});
		btn.setFont(new Font("Tahoma", Font.PLAIN, 14));
		buttonPanel.add(btn);

		invalidate();
		validate();
		repaint();
	}	

	/**
	 * modifie le texte du bouton
	 * @param text le nouveau texte du bouton
	 */
	public void updateButtonText(String text){
		btn.setText(text);
	}

	/**
	 * modifie le texte du label
	 * @param label le label � modifier
	 * @param text le nouveau texte du label
	 */
	public void updateLabelText(JLabel label, String text){
		label.setText(text);
	}

	/**
	 * permet d'autoriser ou interdire l'�dition d'un champ texte
	 * @param tf champ texte ou mot de passe
	 * @param b  'true' : autorise l'�dition, 'false' interdit l'�dition
	 */
	public void updateFieldEdition(JTextField tf, boolean b){
		tf.setEditable(b);
	}

	public void updateFieldText(JTextField tf, String text){
		tf.setText(text);
	}

	public void updateComboBoxEdition(JComboBox cb, boolean b){
		cb.setEditable(b);
	}

	public void updateComboBoxValue(JComboBox cb, Civility civil){
		cb.setSelectedItem(civil);
	}

	public JLabel getCardStatusLabel() {
		return cardStatusLabel;
	}

	public JLabel getCardUidLabel() {
		return cardUidLabel;
	}


	public JComboBox getComboBox() {
		return comboBox;
	}

	public void setComboBox(JComboBox comboBox) {
		//		this.comboBox = comboBox;
	}

	public JTextField getNomField() {
		return nomField;
	}

	public JTextField getPrenomField() {
		return prenomField;
	}

	public JPasswordField getPasswordField() {
		return passwordField;
	}

	public JPasswordField getConfirmPasswordField() {
		return confirmPasswordField;
	}


}
